$(function(){
        var token = localStorage.getItem("token")
        console.log(token)
        var rightBar = $('.navbar-right')

        if (token) {
            AjaxIO.post('/login/decrypt', {token: token}, function(results) {
                console.log(results.data.decryptedToken)

                var personal_li = $('<li><a href="personal.html"> 个人中心 </a></li><a href="/secure/notification/list" class="badge-container notification-badge-container" title="通知"><span class="glyphicon glyphicon-bullhorn hidden-lt-ie8"></span><span class="visible-lt-ie8">通知</span></a></li>')
                var readed_li = $('<li id="courseRecord" class="dropdown hidden-lt-ie8"><a data-toggle="dropdown" class="dropdown-toggle" href="#">学习记录 <b class="caret"></b> </a></li>')
                var user_li = $('<li class="dropdown hidden-lt-ie8"><a href="#" class="dropdown-toggle" data-toggle="dropdown">'+results.data.username+'<b class="caret"></b></a><ul class="dropdown-menu"><li><a href="userIndex.html"><i class="glyphicon glyphicon-home"></i> 我的主页</a></li><li class="divider"></li><li><a id="logout" href="#" javascript:;><i class="glyphicon glyphicon-off"></i> 退出</a></li></ul></li>')

                rightBar.append(personal_li)
                rightBar.append(readed_li)
                rightBar.append(user_li)
            });
        } else {  
            rightBar.append('<li><a href="login.html">登录</a></li><li><a href="register.html">注册</a></li>')
        }

        $(document).on('click','#logout',function(){

            AjaxIO.post('/logout', {}, function(results) {
                if (results.data.success) {
                    localStorage.removeItem("token")
                    location.href = "index.html"
                } else {}
            });
        })
})